<template>

    <div>
      <tr>
        <td>图片：</td>
        <td><input type="file" @change="upload"></td>
      </tr>

    </div>
</template>

<script>
    export default {
        name: "uploadimg",
      data:function () {
        return{

        }
      },
      methods:{
          upload:function (e) {
            //获取存储id
            let uid = sessionStorage.getItem('uid');
            //获取文件
            let file = e.target.files[0];
            //声明表单数据
            let formdata = new FormData();
            formdata.append('uid', uid);
            formdata.append('file', file, file.name);
            // 定义请求头
            let config = {headers:{'Content-Type': 'multipart/form-data'}};

            // 请求后台
            this.axios({
              url:'http://localhost:8000/uploadimg/',
              method:'post',
              data:formdata
            }).then(res=>{
              if(res.data.code==200){
                console.log(res.data.message)
              }else {
                console.log((res.data.message))
              }
            })
          }
      }
    }
</script>

<style scoped>

</style>
